import { useApi } from "@/api";
import { BookListParam, Content, EBook } from "@/views/type";

import { defineStore } from "pinia";
import { ref } from "vue";
const api = useApi();

 const  useEbooks =defineStore('ebook',()=>{

    //请求电子书列表    
    const ebooks = ref<EBook[]>([]);
    const total = ref(0);

    async function  getEbooks(params:BookListParam ){
        const data = await api.booklist<Content<EBook>>(params);
        ebooks.value = data.list!;
        total.value = data.total!;

    }




    return {
        ebooks,
        total,
        getEbooks
    }  
},{persist:true})


export  default useEbooks 